//
//  DoYouLoveCell.m
//  wtshoppingcite
//
//  Created by Baojia-LC on 14-10-20.
//  Copyright (c) 2014年 TW. All rights reserved.
//

#import "DoYouLoveCell.h"

@implementation DoYouLoveCell

- (void)awakeFromNib {
    // Initialization code
}


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}

-(void)createSubViews{
    
    _iconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 90, 60)];
    _iconImageView.backgroundColor = [UIColor greenColor];
    [self.contentView addSubview:_iconImageView];
    
    _titleLabel = [self createLabelWithFrame:CGRectMake(_iconImageView.right+10, _iconImageView.top, 170, 17) text:@"" font:16 textAli:NSTextAlignmentLeft textColor:COLOR_RGB(9, 9, 9)];
    [self.contentView addSubview:_titleLabel];
    
    _subtitleLabel = [self createLabelWithFrame:CGRectMake(_iconImageView.right+10, _titleLabel.bottom+3, 170, 16) text:@"" font:14 textAli:NSTextAlignmentLeft textColor:COLOR_RGB(95, 95, 95)];
    [self.contentView addSubview:_subtitleLabel];
    
    _distanceLabel = [self createLabelWithFrame:CGRectMake(_titleLabel.right, _titleLabel.top, 120, 20) text:@"" font:12 textAli:NSTextAlignmentLeft textColor:COLOR_RGB(95, 95, 95)];
    [self.contentView addSubview:_distanceLabel];
    
    _discountPriceLabel = [[AttrPriceLabel alloc] initWithFrame:CGRectMake(_titleLabel.left, _subtitleLabel.bottom, 60, 20)];
    _discountPriceLabel.font = [UIFont systemFontOfSize: 16];
    _discountPriceLabel.textColor = COLOR_RGB(147, 147, 147);
    //    [_discountPriceLabel setPriceType:1 text:@"324"];
    [self.contentView addSubview:_discountPriceLabel];
    
    _passPriceLabel = [[AttrPriceLabel alloc] initWithFrame:CGRectMake(_discountPriceLabel.right+5, _discountPriceLabel.top, 60, 20)];
    [self.contentView addSubview:_passPriceLabel];
    
    _buycountLabel = [self createLabelWithFrame:CGRectMake(_passPriceLabel.right+10, _subtitleLabel.bottom+5, 60, 16) text:@"已售" font:12 textAli:NSTextAlignmentLeft textColor:COLOR_RGB(95, 95, 95)];
    [self.contentView addSubview:_buycountLabel];
    
}

-(void)setDoYouLoveModel:(DoYouLoveModel *)doYouLoveModel{
    
    if(_doYouLoveModel != doYouLoveModel){
        _iconImageView.backgroundColor = [UIColor grayColor];
        _titleLabel.text = doYouLoveModel.title;
        _subtitleLabel.text = doYouLoveModel.subtitle;
        _distanceLabel.text = doYouLoveModel.distance;
        [_discountPriceLabel setPriceType:1 text:doYouLoveModel.discountprice];
        CGSize size = [doYouLoveModel.discountprice getSizeOfStringFontSize:14 constroSize:CGSizeMake(60, MAXFLOAT)];
        _discountPriceLabel.width  =size.width;
        _passPriceLabel.left = _discountPriceLabel.right+5;
        [_passPriceLabel setPriceType:2 text:doYouLoveModel.passprice];
        _buycountLabel.text = doYouLoveModel.buycount;
    }
}

-(UILabel*)createLabelWithFrame:(CGRect)frame text:(NSString*)text font:(int)font textAli:(NSTextAlignment)alig textColor:(UIColor*)tc{
    if(text == nil)
        text = @"";
    UILabel* label = [[UILabel alloc] initWithFrame:frame];
    label.text = text;
    label.font = [UIFont systemFontOfSize:font];
    label.textAlignment = alig;
    label.textColor = tc;
    label.backgroundColor = [UIColor clearColor];
    return label;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
